package com.gitee.neuray.security.common.rest;

import com.gitee.neuray.security.common.biz.MultBaseBiz;
import com.gitee.neuray.security.common.entity.MultBaseEntity;
import com.gitee.neuray.security.common.msg.ObjectRestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author: zhhongyu
 * @description: 多表方式公共controller
 * @since: Create in 12:20 2020/3/22
 */
public class MultBaseController<Biz extends MultBaseBiz> {
    @Autowired
    private Biz baseBiz;
    @RequestMapping(value = "", method = RequestMethod.POST)
    @ResponseBody
    public <T extends MultBaseEntity> ObjectRestResponse insert(T entity){
        baseBiz.insert(entity);
        return new ObjectRestResponse().rel(true).data(true);
    }
    @RequestMapping(value = "", method = RequestMethod.PUT)
    @ResponseBody
    public <T extends MultBaseEntity> ObjectRestResponse update(T entity){
        baseBiz.update(entity);
        return new ObjectRestResponse().rel(true).data(true);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public ObjectRestResponse remove(@PathVariable String id) {
        baseBiz.deleteById(id);
        return new ObjectRestResponse().rel(true).data(true);
    }
}
